package com.zhiyou100.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 过滤器 测试类
 * 注解形式
 *
 * @author yang
 */
@Slf4j
@WebFilter(filterName = "FilterTest02", urlPatterns = "/*")
@Component
public class FilterTest02 implements Filter {
    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        final HttpServletRequest request1 = (HttpServletRequest) req;
        final String path = request1.getServletPath();
        log.error(" FilterTest02 执行了，拦截到请求 {} ", path);
        chain.doFilter(req, resp);
    }

    @Override
    public void init(FilterConfig config) throws ServletException {

    }

}
